#!/bin/bash

ISO_APPLICATION="Debian Live NFC"
ISO_VOLUME="Debian live NFC $(date +%Y%m%d)"
ISO_PUBLISHER="https://code.google.com/p/nfc-live"
SUPPORT=iso-hybrid
DISTRO=wheezy
ARCH=i386
MIRROR="http://ftp.be.debian.org/debian/"
# Beware if false, some packages have to be re-introduced, e.g. user-setup
# cf http://live.debian.net/manual/3.x/html/live-manual.en.html#452
APTRECOMMENDS=true
FIRMWARECHROOT=true

cd live || exit 1
sudo lb clean
sudo rm -rf config

# bootappend-live: see man live-boot & live-config
# group dialout: for serial boards such as OpenPCD2
lb config \
  --clean \
  --cache true \
  --zsync false \
  --binary-images $SUPPORT \
  --mode debian \
  --distribution $DISTRO \
  --architectures $ARCH \
  --mirror-bootstrap $MIRROR \
  --mirror-binary "$MIRROR" \
  --iso-application "$ISO_APPLICATION" \
  --iso-volume "$ISO_VOLUME" \
  --iso-publisher "$ISO_PUBLISHER" \
  --apt-recommends $APTRECOMMENDS \
  --archive-areas "main contrib non-free" \
  --firmware-chroot $FIRMWARECHROOT

sudo rsync -av ../content_for_iso/@config/ config
sudo chown -R root:root config/includes.binary
sudo find config/includes.binary -type d -exec chmod 755 {} \;
sudo find config/includes.binary -type f -exec chmod 644 {} \;
sudo chown -R root:root config/includes.chroot
sudo find config/includes.chroot -type d -exec chmod 755 {} \;
sudo find config/includes.chroot -type f -exec chmod 644 {} \;
sudo chmod +x config/includes.chroot/usr/local/bin/*
sudo chmod +x config/includes.chroot/root/*.sh
sudo lb build
